package com.xin.ruanjian.omsystem.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xin.ruanjian.omsystem.R;
import com.xin.ruanjian.omsystem.model.ShopCarModel;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by local123 on 2018/2/28.
 */

public class OrderConfirmAdapter extends RecyclerView.Adapter<OrderConfirmAdapter.ViewHolder> {
    private Context context;
    private List<ShopCarModel> mData;

    public OrderConfirmAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<ShopCarModel> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    public OrderConfirmAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv_order_confirm_dish_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(OrderConfirmAdapter.ViewHolder holder, int position) {
        holder.tvDishName.setText(mData.get(position).getdName());
        holder.tvDishPrice.setText("¥" + mData.get(position).getdPrice());
        holder.tvDishNum.setText("×" + mData.get(position).getdNum());
    }

    @Override
    public int getItemCount() {
        if (mData != null) {
            return mData.size();
        }
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_dish_name)
        TextView tvDishName;
        @BindView(R.id.tv_dish_num)
        TextView tvDishNum;
        @BindView(R.id.tv_dish_price)
        TextView tvDishPrice;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
